/*
 * @Author: 码上talk|RC
 * @Date: 2021-05-01 11:32:19
 * @LastEditTime: 2021-08-11 09:40:04
 * @LastEditors: 码上talk|RC
 * @Description:
 * @FilePath: /ma-portal/model/entity/goods/goodsItems.js
 * @微信:  13680065830
 * @邮箱:  3189482282@qq.com
 * @oops: Just do what I think it is right
 */
import _ from 'lodash'
import Entity from '../../entity.class.js';

const _tableField = {
  goodsId: {
    type: 'int',
    default: 0
  },
  name: {
    type: 'string',
    default: ''
  },
  specJson: {
    type: 'string',
    do: {
      parse: true
    },
    default: ''
  },
  amount: {
    type: 'int',
    default: 0
  },
  stock: {
    type: 'int',
    default: 0
  },
  barCode: {
    type: 'string',
    default: ''
  },
  stockFreeze: {
    type: 'int',
    default: 0
  }
};

class GoodsItems extends Entity {
  static _requestConfig = {
    app: 'portal',
    domain: 'goods'
  }

  static _form = {}

  static options = {}

  constructor (goodsItems) {
    super(goodsItems, { _tableField });
  }

  specColorStr () {
    return _.get(_.find(this.specJson, x => { return x.key === '颜色' }), 'value');
  }

  specSizeStr () {
    return _.get(_.find(this.specJson, x => { return x.key === '尺码' }), 'value');
  }

  specJson2str () {
    return this.specJson.map(i => i.value).join('/');
  }

}

export default GoodsItems;
